package Text;
import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.junit.Test;
import java.sql.*;
import java.util.List;

public class C3p0Text {
    @Test()
        public void testC3p0() throws SQLException {
        ComboPooledDataSource com = new ComboPooledDataSource();
        Connection connection = com.getConnection();
        PreparedStatement ps = connection.prepareStatement("SELECT *FROM student");
        ResultSet resultSet = ps.executeQuery();
        while (resultSet.next()){
            int id = resultSet.getInt("sid");
            String name = resultSet.getString("name");
            int age = resultSet.getInt("age");
            Date birthday = resultSet.getDate("birthday");
            System.out.println(id+"===="+name+"===="+age+"===="+birthday);
        }
        com.setMaxPoolSize(10);
        for (int i = 0; i <10 ; i++) {
            System.out.println(com);
        }
        resultSet.close();
        ps.close();
        connection.close();
    }
    @Test
    public void druid1() throws Exception {
        Connection connection = DruidUtils.getConnection();
        PreparedStatement preparedStatement = connection.prepareStatement("select * from student");
        ResultSet resultSet = preparedStatement.executeQuery();
        while (resultSet.next()){
            int id = resultSet.getInt("sid");
            String name = resultSet.getString("name");
            int age = resultSet.getInt("age");
            String birthday = resultSet.getString("birthday");
            System.out.println(id+"===="+name+"===="+age+"===="+birthday);
        }
        DruidUtils.close(connection,preparedStatement,resultSet);
    }
    @Test
    public void druid() throws Exception {
        QueryRunner queryRunner = new QueryRunner(DruidUtils.getDataSource());
        BeanListHandler<Student> studentBeanListHandler = new BeanListHandler<Student>(Student.class);
        List<Student> query = queryRunner.query("select * from student", studentBeanListHandler);

    }
}
